<?php


namespace App\Controller\Admin;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Admin\UserBlockRequest;
use App\Request\Admin\UserIndexRequest;
use App\Service\Admin\UserService;
use Hyperf\Di\Annotation\Inject;

class UserController extends AbstractController
{

    /**
     * @Inject()
     * @var UserService
     */
    protected $userService;

    /**
     * @OperationLog(event="获取用户列表",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index(UserIndexRequest $request)
    {
        $where = $request->validated();
        $lists = $this->userService->index($where);
        return $this->response->success($lists);
    }

    /**
     * @OperationLog(event="用户管理-封号",platform="admin")
     * @param int $userId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function block(int $userId)
    {
        $this->userService->block($userId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="用户管理-解封",platform="admin")
     * @param int $userId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function unblock(int $userId)
    {
        $this->userService->unblock($userId);
        return $this->response->success();
    }
}